/**
 * Created by leiweibo on 7/25/15.
 */

var app = angular.module('researchservice', []);

app.factory('ResearchService', function($http, BaseService) {
  return {
    create:  function(data, success, error) {
      $http.post(BaseService.baseUrl + '/research/create', data).success(success).error(error);
    },
    delete: function(data, success, error) {
      $http.delete(BaseService.baseUrl + '/research/delete?id=' + data.id).success(success).error(error);
    },
    update: function(data, success, error) {
      $http.put(BaseService.baseUrl + '/research/update', data).success(success).error(error);
    },
    list: function(doctor, pageNo, pageSize, params, success) {
      var filterCondition = params.search.predicateObject;
      var queryStr = '';
      if (filterCondition) {
        if (filterCondition.title) {
          queryStr += ('&title=' + filterCondition.title);
        }
      }

      if (doctor) {
        $http.get(BaseService.baseUrl + '/research/list?id='+ doctor + '&pageNo=' + pageNo + '&pageSize=' + pageSize + queryStr).success(success);
      } else {
        $http.get(BaseService.baseUrl + '/research/list?pageNo=' + pageNo + '&pageSize=' + pageSize + queryStr).success(success);
      }
    }
  }
}).factory('ResearchData', function() {
  var savedData = {};
  function set(data) {
    savedData = data;
  }

  function get() {
    return savedData
  }

  return {
    get: get,
    set: set
  }
});
